home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: undergrad.math.uwaterloo.ca!clgonsal
- From: clgonsal@undergrad.math.uwaterloo.ca (Carl Laurence Gonsalves)
- Subject: Re: Watch out! C "gotcha!"
- Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
- Message-ID: <DMvM31.1uw@undergrad.math.uwaterloo.ca>
- Date: Fri, 16 Feb 1996 16:06:37 GMT
- References: <4fthhh$7th@blackice.winternet.com> <4g01ss$hgj@sun001.spd.dsccc.com>
- Nntp-Posting-Host: cayley.uwaterloo.ca
- Organization: University of Waterloo
-
- In article <4g01ss$hgj@sun001.spd.dsccc.com>,
- Mike McCarty <jmccarty@spd.dsccc.com> wrote:
- >In article <4fthhh$7th@blackice.winternet.com>,
- >Michael Schwarz <mschwarz@winternet.com> wrote:
- >)Many of you may already know this, but even after ten years of coding
- >)in C, this took my by surprise at first. A co-worker and I were looking
- >)at some library C code where I work and we noticed that the "default"
- >)clause of one of the switches was misspelled as "defalt."
- >[stuff cut]
- >
- >)The thing that scares me the most about this is that either I've never before
- >)made this particular mistake or for the last ten years I've been leaving
- >)behind a number of ticking code bombs...
- >
- >I know of no way to make a compiler catch spelling mistakes on labels
- >except by doing what Pascal does - force declaration of labels. The
- >exact same problem (only worse) occurs in Fortran where misspelled
- >variables "declare themselves". There is no solution except to require
- >declarations.
-
- It would also be possible for the compiler to warn about unused labels.
- I just tried it with Watcom C and it *does* warn about this. Hmmm... Yet
- another reason to turn on all warnings...
-
- Here's the test program:
-
- #include <stdio.h>
-
- int
- main(){
- puts( "foo" );
- defalt:
- puts( "bar" );
-
- return 0;
- }
-
- --
- Carl Laurence Gonsalves - clgonsal@undergrad.math.uwaterloo.ca
- Computer Science, University of Waterloo
- http://www.undergrad.math.uwaterloo.ca/~clgonsal/
- http://www.csclub.uwaterloo.ca/~clgonsal/
-